<?php
/**
 * initd for SHELL environmet
 *
 * @version 0.2a
 */

// No direct access
defined( "__DEENZO__" ) or die( "deenzo$" );

// Loading dependencies
coreutil( "string" ) or kill( "string$" );

function initd() {

    /* Init Database socket */	
    DB() or kill( "DB$" );
    
    /* INITTAB to system scripts */
    inittab( "-runlevel 2 -kind initd -uid root" );
	
    /* Resolving Command-line params */
    $argv = server( "argv" );
    
    unset( $argv[0] ); 
    
    $argv = (object) cmdl( join( " ", $argv ) );
     
    /* Load CROND */
    if ( $argv->daemon ) {
    
        sh( __DIR__ . "/$argv->daemon", "-of" ) or kill( "$argv->daemon$" );
        
        // Calling to FUNC
        if ( $func = $argv->func ) {
			
            unset( $argv->func, $argv->daemon );
        	
            $args = att( (array) $argv, "-c" );
        	
            // Executing FUNC and passing ARGS
            eval( "$func( \"$args\" );" );
        }   
    }
}

function shutdown() {
    
    inittab( "-runlevel 2 -kind shutdown -uid root" );
    
}